FROM redis:alpine

# 定义时区
ENV TZ=PRC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && echo $TZ > /etc/timezone

# 定义运行用户
ENV APP_HOME=/app
ENV APP_USER=app

RUN addgroup -S -g 2779 $APP_USER \
  ; adduser -S -G $APP_USER -u 2770 $APP_USER \
  ; mkdir -p $APP_HOME \
  ; chown -R $APP_USER:$APP_USER $APP_HOME

WORKDIR $APP_HOME


# 维护者
MAINTAINER app

# 可选配置项
ENV SERVER_PORT=6379
ENV PARAMS=""

# 添加资源
COPY assets/redis-@spring.env@.conf /etc/redis/redis.conf

RUN mkdir -p  /usr/share/redis \
    ; mkdir -p /var/cache/redis \
    ; mkdir -p /var/log/redis \
    ; mkdir -p /etc/redis \
    ; mkdir -p /run \
    ; chown -R $APP_USER:$APP_USER /usr/share/redis \
    ; chown -R $APP_USER:$APP_USER /var/cache/redis \
    ; chown -R $APP_USER:$APP_USER /var/log/redis \
    ; chown -R $APP_USER:$APP_USER /etc/redis \
    ; chown -R $APP_USER:$APP_USER /run

# 执行最终降权运行
RUN chown -R $APP_USER:$APP_USER $APP_HOME

USER 2770
# 暴露端口
EXPOSE $SERVER_PORT

ENTRYPOINT ["sh","-c","redis-server /etc/redis/redis.conf $PARAMS"]